package com.ruoyi.crm.controller;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.MongoLog;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.domain.Clue;
import com.ruoyi.crm.domain.vo.BusinessVo;
import com.ruoyi.crm.service.IBusinessService;
import com.ruoyi.crm.service.IClueService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/crm/businesss")
public class BusinessTrackController extends BaseController {

    @Resource
    private IBusinessService businessService;

//    @Log(title = "商机")
    @MongoLog(tableName = MongoLog.TableName.BUSINESS,title = "商机",businessType = BusinessType.INSERT )
    @PostMapping
    public AjaxResult add(@RequestBody BusinessVo businessVo){
        businessVo.setStatus(Clue.Status.TRACKING.getValue());
        return toAjax(businessService.updateBusiness(businessVo));
    }
    /**
     * 踢回公海
     */
   @PreAuthorize("@ss.hasPermi('crm:business:edit')")
   //    @Log(title = "商机")
   @MongoLog(tableName = MongoLog.TableName.BUSINESS,title = "商机",businessType = BusinessType.INSERT )
   @PutMapping("/giveBack/{id}")
  public AjaxResult giveBack(@RequestBody Map<String,Object> body){
        return toAjax(businessService.giveBack(Long.valueOf(""+body.get("id"))));
   }
}
